<template>
  <div class="common-layout">
    <el-container>
      <el-header class="system-header">
        <div class="header-left">
          <el-icon class="logo-icon"><Connection /></el-icon>
          <span class="system-title">智慧康宁医院</span>
          <span class="system-subtitle">管理系统</span>
        </div>
        <div class="user-info">
          <span class="user-info-item"><el-icon><User /></el-icon> 用户：<b>{{store.use.name}}</b></span>
          <span class="user-info-item"><el-icon><UserFilled /></el-icon> 角色：<b>{{store.use.roleName}}</b></span>
          <el-button link class="logout-button" @click="out">
            <el-icon class="logout-icon"><SwitchButton /></el-icon>
            退出
          </el-button>
        </div> 
      </el-header>
      <el-container class="main-container">
        <el-aside :width="isCollapse ? '64px' : '220px'" class="sidebar">
          <div class="menu-header">
            <el-button link @click="isCollapse = !isCollapse" class="collapse-button">
              <el-icon :class="{'is-collapsed': isCollapse}"><Fold /></el-icon>
            </el-button>
          </div>
          <el-menu
              router
              default-active="0"
              class="el-menu-vertical-demo"
              :collapse="isCollapse"
              background-color="#006666"
              text-color="#b3d9d9"
              active-text-color="#ffffff"
              unique-opened
          >
          <!-- 渲染父级菜单 -->
            <el-sub-menu v-for="item in store.menus" :index="item.url" :key="item.url">
              <template #title>
                <el-icon class="menu-icon"><Setting /></el-icon>
                <span>{{item.label}}</span>
              </template>

                <el-menu-item-group v-for="child in item.children" :key="child.url">
                    <el-menu-item :index="child.url">
                      <el-icon><Lock /></el-icon>
                      <span>{{child.label}}</span>
                    </el-menu-item>
                </el-menu-item-group>
              </el-sub-menu>
          </el-menu>
        </el-aside>
        <el-main class="main-content">
            <div class="page-header">
              <h2 class="page-title">欢迎使用智慧康宁医院管理系统</h2>
              <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/Main' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>当前页面</el-breadcrumb-item>
              </el-breadcrumb>
            </div>
            <div class="page-content">
              <RouterView/>
            </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { useCounterStore } from '@/stores/counter';
const store = useCounterStore();
import { useRouter } from 'vue-router'
const router = useRouter();
import { onMounted, ref } from 'vue'

onMounted(()=>{
  store.getMenus();
})
//退出功能
const out=()=>{
  store.use.name ='';
  store.use.roleId=0;
  store.use.roleName='';
  localStorage.removeItem('token');
  localStorage.removeItem('refreshToken');
  router.push({path:"/"});
}
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
  Lock,
  User,
  UserFilled,
  SwitchButton,
  Fold,
  Connection
} from '@element-plus/icons-vue'
//控制菜单是否展开
const isCollapse = ref(false)
</script>
<style>
.common-layout {
  height: 100vh;
  background: linear-gradient(135deg, #e0f7f7 0%, #f0f9f9 100%);
  overflow: hidden;
}

.system-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(90deg, #ffffff 0%, #f8fdfd 100%);
  color: #2c3e50;
  padding: 0 20px;
  box-shadow: 0 2px 12px rgba(0, 166, 166, 0.15);
  border: none;
  height: 60px;
  position: relative;
  z-index: 10;
  border-bottom: 2px solid #20b2aa;
}

.header-left {
  display: flex;
  align-items: center;
}

.logo-icon {
  font-size: 28px;
  color: #00a6a6;
  margin-right: 12px;
  filter: drop-shadow(0 2px 4px rgba(0, 166, 166, 0.3));
}

.system-title {
  font-size: 22px;
  font-weight: 700;
  color: #006666;
  letter-spacing: 0.5px;
  position: relative;
  margin-right: 8px;
}

.system-subtitle {
  font-size: 14px;
  font-weight: 400;
  color: #20b2aa;
  letter-spacing: 0.3px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-info-item {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: 6px;
  color: #006666;
  background: rgba(32, 178, 170, 0.1);
  border: 1px solid rgba(32, 178, 170, 0.2);
  transition: all 0.3s ease;
}

.user-info-item:hover {
  background: rgba(32, 178, 170, 0.15);
  border-color: rgba(32, 178, 170, 0.3);
  transform: translateY(-1px);
}

.logout-button {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #e74c3c;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 6px;
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid rgba(231, 76, 60, 0.2);
  transition: all 0.3s ease;
}

.logout-button:hover {
  background: rgba(231, 76, 60, 0.15);
  border-color: rgba(231, 76, 60, 0.3);
  transform: translateY(-1px);
}

.logout-icon {
  font-size: 16px;
}

.main-container {
  height: calc(100vh - 60px);
  overflow: hidden;
}

.sidebar {
  background: linear-gradient(180deg, #006666 0%, #004d4d 100%);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  box-shadow: 2px 0 8px rgba(0, 102, 102, 0.2);
}

.menu-header {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
}

.collapse-button {
  width: 100%;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.8);
  background: transparent;
  border: none;
  transition: all 0.3s ease;
}

.collapse-button:hover {
  color: white;
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.1);
}

.is-collapsed {
  transform: rotate(180deg);
}

.el-menu {
  border-right: none !important;
  transition: width 0.3s ease-in-out;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 220px;
  min-height: 300px;
}

.el-sub-menu__title {
  position: relative;
  font-size: 14px;
  padding-left: 20px !important;
  height: 50px !important;
  line-height: 50px !important;
}

.el-menu-item {
  font-size: 14px;
  padding-left: 40px !important;
  height: 45px !important;
  line-height: 45px !important;
  margin: 4px 0;
}

.el-icon {
  margin-right: 8px;
  transition: all 0.3s;
}

.menu-icon {
  font-size: 16px;
}

.el-sub-menu__title:hover, .el-menu-item:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
  transform: translateX(4px);
}

.el-menu-item.is-active {
  background: linear-gradient(90deg, #20b2aa 0%, #4ecdc4 100%) !important;
  color: white !important;
  box-shadow: 0 2px 8px rgba(32, 178, 170, 0.3);
  border-radius: 0 25px 25px 0;
  margin-right: 8px;
}

.main-content {
  background: transparent;
  padding: 16px;
  overflow: hidden;
  transition: all 0.3s ease;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.page-header {
  background: linear-gradient(135deg, #ffffff 0%, #f8fdfd 100%);
  padding: 20px 28px;
  margin-bottom: 16px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 166, 166, 0.1);
  border: 1px solid rgba(32, 178, 170, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #006666;
  text-shadow: 0 1px 2px rgba(0, 102, 102, 0.1);
}

.page-content {
  flex: 1;
  background: linear-gradient(135deg, #ffffff 0%, #fafefe 100%);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 4px 16px rgba(0, 166, 166, 0.08);
  border: 1px solid rgba(32, 178, 170, 0.08);
  overflow: auto;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;
}

html {
  overflow: hidden;
}

/* 医疗主题增强样式 */
.el-sub-menu__title, .el-menu-item {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.el-sub-menu__title {
  border-left: 3px solid transparent;
}

.el-sub-menu.is-opened > .el-sub-menu__title {
  border-left-color: #4ecdc4;
  background: rgba(255, 255, 255, 0.08) !important;
}

.el-menu-item {
  border-left: 3px solid transparent;
  position: relative;
}

.el-menu-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  background: #4ecdc4;
  border-radius: 0 2px 2px 0;
  transition: all 0.3s ease;
}

.el-menu-item:hover::before {
  width: 3px;
  height: 20px;
}

/* 面包屑样式优化 */
.el-breadcrumb {
  font-size: 14px;
}

.el-breadcrumb__item {
  color: #20b2aa;
}

.el-breadcrumb__item:last-child {
  color: #006666;
  font-weight: 500;
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(32, 178, 170, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #20b2aa 0%, #4ecdc4 100%);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #4ecdc4 0%, #20b2aa 100%);
}
</style>